package hash表;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

public class Solution349 {


    public int[] intersection(int[] nums1, int[] nums2) {

        Set<Integer> set1 = new HashSet<>();
        Set<Integer> resultSet = new HashSet<>();

        for (int i = 0; i < nums1.length; i++) {
            set1.add(nums1[i]);
        }
        for (int i = 0; i < nums2.length; i++) {
            if (set1.contains(nums2[i])) {
                resultSet.add(nums2[i]);
            }
        }
        int[] result = new int[resultSet.size()];
        int k = 0;
        for (int i : resultSet) {
            result[k++] = i;
        }
        return result;
    }
}
